{% extends 'common/base.html' %}
{% from 'common/macro.html' import pagination_show%}
{% block title %}

    首页
{% endblock %}

{% block page_content %}
    {{ wtf.quick_form(form) }}
    {% for post in posts %}
        <div class="media">
            <div class="media-left media-middle">
                <a href="#">
                    <img class="media-object" src="{{ url_for('static',filename='upload/'+post.user.icon) }}" alt="用户头像">
                </a>
            </div>
            <div class="media-body">
                <div style="float: right">{{ moment(post.timestamp).fromNow() }}</div>
                <h4 class="media-heading">{{ post.user.username }}</h4>
                {{ post.content }}
                ...
            </div>
            {% if current_user.is_authenticated %}
                <div url="{{ url_for("posts.collect",pid=post.id) }}" class="collect">{% if current_user.is_favorite(post.id)%}取消收藏{% else %}收藏{% endif %}</div>
            {% endif %}
        </div>
    {% endfor %}
{#    {{ pagination_show(pagination,'main.index',id=1,username='afsdf') }}#}
      {{ pagination.links }}
{% endblock %}

{% block scripts %}
    {{ super() }} 
{#    jQuery#}
    <script type="text/javascript">
        $(function () {
            $('.collect').click(function () {
                _this = this
                $.get($(this).attr('url'),function () {
                    if($(_this).text() == "收藏"){
                        $(_this).text('取消收藏')
                    }else{
                        $(_this).text('收藏')

                    }
                })
            })
        })
    </script>
{% endblock %}